home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-05-01 | 10.5 KB | 450 lines | [TEXT/MPS ] |
- // USectionMgr.cp
- // Copyright © 1984-1991 by Apple Computer Inc. All rights reserved.
-
- #ifndef __USECTIONMGR__
- #include <USectionMgr.h>
- #endif
-
- #ifndef __UFILE__
- #include <UFile.h>
- #endif
-
- #ifndef __UAPPLEEVENTS__
- #include <UAppleEvents.h>
- #endif
-
- #ifndef __UAPPLICATION__
- #include <UApplication.h>
- #endif
-
- #ifndef __USECTION__
- #include <USection.h>
- #endif
-
- #ifndef __UDOCUMENT__
- #include <UDocument.h>
- #endif
-
- #ifndef __UPRINTHANDLER__
- #include <UPrintHandler.h>
- #endif
-
- #ifndef __BALLOONS__
- #include <Balloons.h>
- #endif
-
- #ifndef __UVIEW__
- #include <UView.h>
- #endif
-
- #ifndef __UADORNERS__
- #include <UAdorners.h>
- #endif
-
- #ifndef __UWINDOW__
- #include <UWindow.h>
- #endif
-
- #ifndef __USCROLLER__
- #include <UScroller.h>
- #endif
-
- #ifndef __UFILEBASEDDOCUMENT__
- #include <UFileBasedDocument.h>
- #endif
-
- #ifndef __UEDITIONDOCUMENT__
- #include <UEditionDocument.h>
- #endif
-
- #ifndef __UFAILURE__
- #include <UFailure.h>
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include <UMacAppUtilities.h>
- #endif
-
- #ifndef __UERRORMGR__
- #include <UErrorMgr.h>
- #endif
-
- #ifndef __UMEMORY__
- #include <UMemory.h>
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef __UMENUMGR__
- #include <UMenuMgr.h>
- #endif
-
- #ifndef __UDESKSCRAPVIEW__
- #include <UDeskScrapView.h>
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include <UMacAppGlobals.h>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __UBUSYCURSOR__
- #include <UBusyCursor.h>
- #endif
-
- #ifndef __UDEBUG__
- #include <UDebug.h>
- #endif
-
- #ifndef __UINSPECTOR__
- #include <UInspector.h>
- #endif
-
- #ifndef __SCRAP__
- #include <Scrap.h>
- #endif
-
- #ifndef __UCLIPBOARDMGR__
- #include <UClipboardMgr.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
-
- #ifndef __SCRIPT__
- #include <Script.h>
- #endif
-
- #ifndef __STDIO__
- #include <StdIO.h>
- #endif
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAInit
-
- pascal void TSectionMgr::ISectionMgr()
-
- {
- this->IBehavior();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAApplicationRes
-
- pascal void TSectionMgr::DoAppleCommand(CmdNumber aCmdNumber,
- const AppleEvent& message,
- const AppleEvent& reply)
- {
- TAppleCommand * theCommand = NULL;
- VOLATILE(theCommand); // needed in failure handling below
-
- if (gConfiguration.hasEditionMgr) // ensure it was initialized
- switch (aCmdNumber)
- {
- case cSectionRead:
- theCommand = new TSectionReadEventCmd;
- break;
-
- case cSectionWrite:
- theCommand = new TSectionWriteEventCmd;
- break;
-
- case cSectionScroll:
- theCommand = new TSectionScrollEventCmd;
- break;
-
- case cSectionCancel:
- theCommand = new TSectionCancelEventCmd;
- break;
- }
-
- if (theCommand)
- {
- FailInfo fi;
-
- if (fi.Try())
- {
- theCommand->InitFromAppleEvent(aCmdNumber, NULL, NULL, message, reply);
- fOwner->PostCommand(theCommand);
-
- fi.Success();
- }
- else // Recover
- {
- theCommand = (TAppleCommand *)FreeIfObject(theCommand);
-
- fi.ReSignal();
- }
- }
- else
- inherited::DoAppleCommand(aCmdNumber, message, reply);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFields
-
- pascal void TSectionMgr::Fields(TObject* obj) // override
-
- {
- obj->DoToField("TSectionMgr", (Ptr)NULL, bClass);
-
- inherited::Fields(obj);
- }
-
- //******************************************************************************************
- // T S e c t i o n C o m m a n d
- //******************************************************************************************
- #pragma segment MACommandRes
-
- pascal void TSectionCommand::ISectionCommand(CmdNumber itsCmdNumber,
- TDocument* itsDocument,
- TView* itsView,
- TSection* itsSection)
-
- {
- this->IAppleCommand(itsCmdNumber, itsDocument, itsView);
- fSection = itsSection;
-
- /* By default, the section commands *don't* cause changes to the document and are
- *not* undoable. If the document changes (e.g. during a section read event) then the
- document should set its change count accordingly to reflect the fact that its data
- has changed, rather than having this command always default to causing changes. */
- fCanUndo = FALSE;
- fCausesChange = FALSE;
- }
-
- //--------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- pascal void TSectionCommand::InitFromAppleEvent(CmdNumber itsCmdNumber,
- TDocument* itsDocument,
- TView* itsView,
- const AppleEvent& itsMessage,
- const AppleEvent& itsReply)// override
-
- {
- SectionHandle aSectionHandle;
-
- inherited::InitFromAppleEvent(itsCmdNumber, itsDocument, itsView, itsMessage, itsReply);
-
- // get the section handle
- fMessage->ReadSectionHandle(keyDirectObject, aSectionHandle);
- if (qDebug && gIntenseDebugging)
- fprintf(stderr, "SectionHandle from AppleEvent = %ld \n", (long)aSectionHandle);
-
- // map the section handle to a section object
- fSection = this->GetSectionObject(aSectionHandle);
- FailNIL(fSection);
- if (qDebug)
- if (!VerboseIsObject(fSection))
- ProgramBreak("the section object appears to be corrupt");
-
- // associate the command correctly
- fChangedObject = fSection->fDocument;
- if (qDebug)
- if (!VerboseIsObject(fChangedObject))
- ProgramBreak("the section object's document appears to be corrupt");
-
- // ensure that the section is registered
- FailOSErr(fSection->Register());
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAApplicationRes
-
- pascal TSection* TSectionCommand::GetSectionObject(SectionHandle aSectionHandle)
- {
- CDocumentIterator iter(gApplication);
- TSection* aSection = NULL;
-
- for (TDocument* aDocument = iter.FirstDocument(); iter.More(); aDocument = iter.NextDocument())
- {
- aSection = ((TEditionDocument *)aDocument)->GetSectionObject(aSectionHandle);
- if (aSection)
- return aSection; // found a TSection, so return it
- }
-
- return NULL; // no TSection found for this SectionHandle
- }
-
- //******************************************************************************************
- // T S e c t i o n R e a d E v e n t C m d
- //******************************************************************************************
- #pragma segment MACommandRes
-
- pascal void TSectionReadEventCmd::ISectionReadEventCmd(CmdNumber itsCmdNumber,
- TDocument* itsDocument,
- TView* itsView,
- TSubscriber* itsSubscriber)
-
- {
- this->ISectionCommand(itsCmdNumber, itsDocument, itsView, itsSubscriber);
- }
-
- //--------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- pascal void TSectionReadEventCmd::DoIt(void) // override
-
- {
- FailInfo fi;
-
- if (fi.Try())
- {
- TSubscriber * aSubscriber = (TSubscriber *)fSection;
-
- if ((!aSubscriber->fDocument->fStopAllEditions) && (aSubscriber->fSectionHandle != NULL) && (aSubscriber->GetUpdateMode() == sumAutomatic))
- aSubscriber->Subscribe();
-
- fi.Success();
- }
- else
- {
- this->ReportError(fi.error, fi.message);
- fi.ReSignal();
- }
- }
-
- //******************************************************************************************
- // T S e c t i o n W r i t e E v e n t C m d
- //******************************************************************************************
- #pragma segment MACommandRes
-
- pascal void TSectionWriteEventCmd::ISectionWriteEventCmd(CmdNumber itsCmdNumber,
- TDocument* itsDocument,
- TView* itsView,
- TPublisher* itsPublisher)
-
- {
- this->ISectionCommand(itsCmdNumber, itsDocument, itsView, itsPublisher);
- }
-
- //--------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- pascal void TSectionWriteEventCmd::DoIt(void) // override
-
- {
- FailInfo fi;
-
- if (fi.Try())
- {
- ((TPublisher *)fSection)->Publish();
-
- fi.Success();
- }
- else
- {
- this->ReportError(fi.error, fi.message);
- fi.ReSignal();
- }
-
- }
-
- //******************************************************************************************
- // T S e c t i o n S c r o l l E v e n t C m d
- //******************************************************************************************
- #pragma segment MACommandRes
-
- pascal void TSectionScrollEventCmd::ISectionScrollEventCmd(CmdNumber itsCmdNumber,
- TDocument* itsDocument,
- TView* itsView,
- TSection* itsSection)
-
- {
- this->ISectionCommand(itsCmdNumber, itsDocument, itsView, itsSection);
- }
-
- //--------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- pascal void TSectionScrollEventCmd::DoIt(void) // override
-
- {
- // at this point, the application has received and processed the 'odoc' AppleEvent
- // so, the window containing the section should be frontmost
-
- FailInfo fi;
-
- if (fi.Try())
- {
- // 1. bring the application to front (using the Process Manager)
- gApplication->MakeFrontProcess();
-
- // 2. tell the document to reveal the selection and select it
- if (fChangedObject)
- ((TDocument*)fChangedObject)->RevealSelection(fSection->fDesignator);
-
- fi.Success();
- }
- else
- {
- this->ReportError(fi.error, fi.message);
- fi.ReSignal();
- }
- }
-
- //******************************************************************************************
- // T S e c t i o n C a n c e l E v e n t C m d
- //******************************************************************************************
- #pragma segment MACommandRes
-
- pascal void TSectionCancelEventCmd::ISectionCancelEventCmd(CmdNumber itsCmdNumber,
- TDocument* itsDocument,
- TView* itsView,
- TSection* itsSection)
-
- {
- this->ISectionCommand(itsCmdNumber, itsDocument, itsView, itsSection);
- }
-
- //--------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- pascal void TSectionCancelEventCmd::DoIt(void) // override
-
- {
- FailInfo fi;
-
- if (fi.Try())
- {
- ((TEditionDocument *)fChangedObject)->CancelSection(fSection, kCancel);
-
- fi.Success();
- }
- else
- {
- this->ReportError(fi.error, fi.message);
- fi.ReSignal();
- }
- }
-
- //******************************************************************************************
- // G l o b a l R o u t i n e s
- //******************************************************************************************
- #pragma segment MAInit
-
- pascal void InitUSectionMgr(void)
-
- {
- TSectionMgr * aSectionMgr = new TSectionMgr; // instantiate a section mgr
- aSectionMgr->ISectionMgr(); // initialize it
- gApplication->AddBehavior(aSectionMgr); // give the application this behavior
- }
-
-
-